package com.czl.base.binding.viewadapter.ratingbar

import android.widget.RatingBar
import androidx.databinding.BindingAdapter
import com.czl.base.binding.command.BindingCommand

/**
 *
 * @Description:
 * @Author: XCH
 * @CreateDate: 2021/12/29 11:30
 */
object ViewAdapter {

    @JvmStatic
    @BindingAdapter(value = ["onRatingBarChangedCommand"], requireAll = false)
    fun onRatingBarChangedCommand(ratingBar: RatingBar, bindingCommand: BindingCommand<Int?>) {
        ratingBar.setOnRatingBarChangeListener() { _, rating, _ ->
            bindingCommand.execute(rating.toInt())
        }
    }

    @JvmStatic
    @BindingAdapter(value = ["ratingStarNum"], requireAll = false)
    fun setStarNum(ratingbar: com.hedgehog.ratingbar.RatingBar, starNum: Double) {
        ratingbar.setStar(starNum.toFloat())
    }
}